package com.test.java;

import java.util.*;

/**
 * 德才论
 * =============================================================
 * Version          Author          Date            Description
 * 1.0              白建         2017/12/15             创建
 * =============================================================
 */
public class Java_6
{

    private static int NUM;

    private static byte MIN, MAX;

    static TreeSet<Student> APlus = new TreeSet<Student>();

    static TreeSet<Student> AMinus = new TreeSet<Student>();

    static TreeSet<Student> BPlus = new TreeSet<Student>();

    static TreeSet<Student> BMinus = new TreeSet<Student>();

    public static void main(String[] args)
    {

        init();
        System.out.println(APlus.size() + AMinus.size() + BPlus.size() + BMinus.size());
        print(APlus);
        print(AMinus);
        print(BPlus);
        print(BMinus);
    }

    private static void init()
    {

        Scanner scanner = new Scanner(System.in);
        NUM = scanner.nextInt();
        MIN = scanner.nextByte();
        MAX = scanner.nextByte();

        for (int i = 0; i < NUM; i++)
        {
            insert(scanner);
        }
    }

    private static void insert(Scanner scanner)
    {


        Student student = new Student();
        student.Stdno = scanner.nextInt();
        student.Moral = scanner.nextByte();
        student.Talent = scanner.nextByte();
        student.Score = student.Moral + student.Talent;

        if (student.Moral < MIN || student.Talent < MIN)
        {
            return;
        }
        if (student.Moral >= MAX && student.Talent >= MAX)
        {
            APlus.add(student);
        }
        else if (student.Moral >= MAX && student.Talent < MAX)
        {
            AMinus.add(student);
        }
        else if (student.Moral < MAX && student.Talent < MAX && student.Moral >= student.Talent)
        {
            BPlus.add(student);
        }
        else
        {
            BMinus.add(student);
        }
    }

    private static void print(TreeSet<Student> set)
    {

        for (Student s : set)
        {
            System.out.println(s.Stdno + " " + s.Moral + " " + s.Talent);
        }
    }

    private static class Student implements Comparable<Student>
    {

        public int Stdno;

        public byte Moral;

        public byte Talent;

        public int Score;

        @Override
        public int compareTo(Student student)
        {

            if (student.Score < this.Score)
            {
                return -1;
            }
            else if (student.Score == this.Score)
            {
                if (student.Moral < this.Moral)
                {
                    return -1;
                }
                else if (student.Moral == this.Moral)
                {
                    if (student.Stdno > this.Stdno)
                    {
                        return -1;
                    }
                }
            }
            return 1;
        }
    }
}
